<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <button onclick="handleClick()">get点击我</button>
  <button onclick="handleClickPost()">post点击我</button>
  <script>
    function postJSON(url, data) {
      return new Promise((resolve, reject) => {
        var xhr = new XMLHttpRequest()
        xhr.open('POST', url, true)
        // xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        xhr.setRequestHeader('Authorization', 'Bearer 4ac8ae97-700a-4abb-80e5-8c2be54eef4e')

        xhr.onreadystatechange = function () {
          if (this.readyState === 4) {
            if (this.status === 200) {
              resolve(JSON.parse(this.responseText))
            } else {
              reject({
                code: this.status,
                response: this.response
              })
            }
          }
        }

        xhr.send(JSON.stringify(data))
      })
    }
    function handleClick() {
      getJSON('http://192.168.30.166:9999/c/country/findAllCountry').then(res => {
        console.log(res)
      }).catch(err => {
        console.log(err)
      })
    }
    function handleClickPost() {
      postJSON('https://www.e-ports.com/c/orders/base/basicEnum', {}).then(res => {
        console.log(res, '1111')
      }).catch(err => {
        console.log(err, '2222')
      })
    }
  </script>
</body>

</html>
